package com.database.controller;


import com.rent.common.api.ApiString;
import com.rent.common.pojo.ResultJSON;
import com.rent.common.utils.ContextUtil;
import com.database.service.ISuperService;

import java.io.Serializable;

/**
 * @Author zhang
 * @create 2022/9/12 10:55
 */
public interface BaseController<T, PK extends Serializable> {

    ISuperService<T, PK> getSuperService();

    default ResultJSON<String> saveSuccess() {
        return ResultJSON.success(ApiString.saveSuccess);
    }

    default ResultJSON<Integer> saveSuccess(Integer id) {
        return ResultJSON.success(ApiString.saveSuccess, id);
    }

    default ResultJSON<String> saveFail(String msg) {
        return ResultJSON.failure(msg);
    }

    default ResultJSON<String> saveFail() {
        return ResultJSON.failure();
    }

    default ResultJSON<T> getFail() {
        return ResultJSON.failure(ApiString.getFailure);
    }

    default ResultJSON<T> getSuccess(T model) {
        return ResultJSON.success(ApiString.getSuccess, model);
    }

    default ResultJSON<String> deleteFail() {
        return ResultJSON.failure(ApiString.deleteFail);
    }

    default ResultJSON<String> deleteFail(String msg) {
        return ResultJSON.failure(msg);
    }

    default ResultJSON<String> deleteSuccess() {
        return ResultJSON.success(ApiString.deleteSuccess);
    }

    default Integer getAccountId() {
        return ContextUtil.getAccountId();
    }
    default String getUsername() {
        return ContextUtil.getUsername();
    }


}
